| Conditions | 2 |
| Total Lines | 18 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | |||
| 2 | /** |
||
| 3 | * Language codes are |
||
| 4 | * [ISO 639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) |
||
| 5 | * and must be a 3 character string. |
||
| 6 | * |
||
| 7 | * This function could also be potentially be used to validate that the given |
||
| 8 | * code is a known code. |
||
| 9 | * |
||
| 10 | * @param languageCode The language code to be validated. |
||
| 11 | * @returns Returns the given language code if valid otherwise throws. |
||
| 12 | */ |
||
| 13 | export function validateLanguageCode(languageCode: string) { |
||
| 14 | if (languageCode.length !== 3) { |
||
| 15 | throw new RangeError( |
||
| 16 | "Language string length must be 3, see ISO 639-2 codes" |
||
| 17 | ) |
||
| 18 | } |
||
| 19 | return languageCode |
||
| 20 | } |
||
| 37 |